import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import local_set from '@dfeidao/atom-web/local/set';
export default async function a001(fd: IFeidaoAiBrowserComponent) {
	// todo
	const url = fd.data.url;
	const page_name = url.match(/.*\/((.*?)\.html)/)[1];
	const last_node = fd.data.node.querySelector('[href="' + page_name + '"]') as HTMLDivElement;
	if (!last_node) {
		return;
	}

	last_node.setAttribute('data-a-b', 'ab');
	if (last_node) {
		if (last_node.dataset.feidaoA !== '1') {
			(last_node.childNodes[0] as HTMLDivElement).setAttribute('data-feidao-dataclas', '3');
		}
		const level_node = last_node.closest('[name="xz"]') as HTMLDivElement;
		if (!level_node) {
			// 一级菜单
			const first_level = last_node.closest('[data-feidao-level="1"]');
			(first_level.firstChild as Element).classList.add('menus');
			(first_level.firstChild as HTMLElement).click();
		} else {
			level_node.style.setProperty('background-color', '#242c3f');
			(level_node.firstChild.firstChild as HTMLDivElement).style.setProperty('color', '#5575d7');
			const anixs = new Array();
			const gpn = (node: Element) => {
				const current_l = node.getAttribute('data-feidao-l');
				const p_node = level_node.closest('[data-feidao-level="' + current_l + '"]');
				if (current_l === '2') {
					anixs.unshift(p_node.parentElement.firstChild);
				} else {
					const dd = p_node.parentElement.querySelector('[name="xz"]');
					anixs.unshift(dd);
					gpn(dd);
				}
			};
			gpn(level_node);
			if (anixs.length > 0) {
				const first_node = anixs[0];
				local_set(fd, 'num', 0);
				first_node.click();
				// 删除数组第一个
				anixs.shift();
				local_set(fd, 'select_node', anixs);
			}
		}
	}
}
